<?php

/**
 * @author huynhtuvinh87
 * @copyright 2013
 */
class File extends CActiveRecord {

    private $_oldTags;

    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{file}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name', 'required'),
            array('create_time, category_id', 'numerical', 'integerOnly' => true),
//            array('file', 'file', 'types' => 'doc, pdf, zip, docx'),
            array('status', 'in', 'range' => array(0, 1)),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'category' => array(self::BELONGS_TO, 'FileCategories', 'category_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'Id',
            'name' => 'Tiêu đề',
            'image' => 'Hình minh họa',
            'category_id' => 'Danh mục',
            'create_time' => 'Ngày nhập',
            'content' => 'Nội dung',
            'state' => 'Tình trạng',
            'alias' => 'Đường dẫn',
            'status' => 'Trạng thái',
            'news' => 'Tin nổi bật'
        );
    }

    
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->addSearchCondition('name', $this->name);
        $criteria->compare('status', $this->status);
        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
            'pagination' => array(
                'pageSize' => '20',
            ),
            'sort' => array(
                'defaultOrder' => 'id DESC'
            ),
        ));
    }

}
